using Unity.VisualScripting;
using UnityEngine;

public class PlayerCharacter : Character
{
    public static PlayerCharacter Instance;
    private Collider2D coll;

    // 重写生命值属性字段，更改生命值时同步更新玩家血条
    public override float CurrentHealth{
        get { return _currentHealth; }
        set{
            _currentHealth = value;
            //更新玩家血条UI
            PlayerEvents.UpdateHP(_currentHealth, maxHealth);
        }
    }
    
    private void Awake()
    {
        Instance = this;
        coll = GetComponent<Collider2D>();
    }

    public override void Start()
    {
        base.Start();
        CurrentHealth = GameManager.Instance.currentHealth;
    }

    // 受伤逻辑
    protected override void Hit(Attack attack)
    {
        GetComponent<PlayerController>().parameter.isHurt = true;

        //时停
        TimeManager.Instance.BulletTime();
        
        //相机震动
        CameraShake.Instance.PlayCameraShake();
    }

    public override void SetHealth(float value)
    {
        base.SetHealth(value);
       

        //伤害飘字
        Color color = value > 0 ? Color.green : Color.red;
        string str = value > 0 ? "+" + value :  value.ToString();
        GameManager.Instance.ShowText(str, transform.position, color);
    }

    // 死亡逻辑
    protected override void Die()
    {
        if (GetComponent<PlayerController>().parameter.isDead) return;
        GetComponent<PlayerController>().parameter.isDead = true;
        coll.enabled = false;
    }
}